package net.stancristian.restnews;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class UserIdentity {
	public Integer Id;
	public String FirstName;
	public String LastName;
	public String Address;
	public String Username;
	public ArrayList<String> Roles;
	
	/*
	 * Parameterless Constructor
	 */
	public UserIdentity()
	{
		Roles = new ArrayList<String>();
	}
	
	/*
	 * Constructor that accepts a json
	 */
	public UserIdentity(JSONObject json)
	{
		try {
			FirstName = json.getString("FirstName");
			LastName = json.getString("LastName");
			Address = json.getString("Address");
			Username = json.getString("Username");
			Roles = new ArrayList<String>();
			JSONArray rolesArray = json.getJSONArray("Roles");
			for(int i = 0; i< rolesArray.length(); i++)
			{
				Roles.add(rolesArray.getString(i));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}
